package cn.chiship.framework.business.core.task;

import cn.chiship.framework.common.annotation.JobAnnotation;
import cn.chiship.framework.upms.biz.system.entity.UpmsQuartzJobLog;
import cn.chiship.framework.upms.biz.system.entity.UpmsQuartzJobLogExample;
import cn.chiship.framework.upms.biz.system.service.UpmsQuartzJobLogService;
import cn.chiship.sdk.core.util.DateUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class QuartzJobJogTask {
    @Resource
    UpmsQuartzJobLogService quartzJobLogService;

    @JobAnnotation("清理一天前所有日志数据")
    public void clearOneDayAgoData() {
        UpmsQuartzJobLogExample upmsQuartzJobLogExample = new UpmsQuartzJobLogExample();
        upmsQuartzJobLogExample.createCriteria().andStartTimeLessThanOrEqualTo(DateUtils.dateTime("yyyy-MM-dd 00:00:00", new SimpleDateFormat("yyyy-MM-dd 00:00:00").format(new Date())).getTime());
        quartzJobLogService.deleteByExample(upmsQuartzJobLogExample);
    }
}
